#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
#include<vector>

int main()
{
    int cur = 0, dest = -1;
    vector<int> arr{1,2,0,6,0,2};
    for (; cur < arr.size(); cur++)
    {
        if (arr[cur] != 0)
        {
            dest++;
        }
        else
        {
            dest += 2;
        }

        if (dest >=arr.size()-1)
        {
            if (dest == arr.size())
            {
                arr[dest - 1] = 0;
                dest -= 2;
                cur--;
            }
            break;
        }
    }

    for (; cur >= 0; cur--)
    {
        if (arr[cur] == 0)
        {
            arr[dest] = arr[dest - 1] = 0;
            dest -= 2;
        }
        else
        {
            arr[dest] = arr[cur];
            dest--;
        }
    }

    for (auto e : arr)
    {
        cout << e << ' ';
    }
}
